package com.pzh.guli.service.edu.controller.api;


import com.pzh.guli.service.base.handler.HandlerException;
import com.pzh.guli.service.base.result.Result;
import com.pzh.guli.service.edu.pojo.vo.OrderVo;
import com.pzh.guli.service.edu.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xzh
 * @since 2022-07-21
 */
@RestController
@RequestMapping("api/trade/order")
public class OrderController {
    @Autowired
    IOrderService orderService;
     @PostMapping("create/{courseId}")
     public Result creatOrder(@PathVariable String courseId, HttpServletRequest request) throws HandlerException {
         String orderInfo=orderService.createOrder(courseId,request);
         return Result.ok().data("item",orderInfo);
     }
     @GetMapping("is-buy-course/{courseId}")
     public Result isBuyCourseByID(@PathVariable String courseId,HttpServletRequest request) throws HandlerException {
        boolean flag= orderService.isBuyCourse(courseId,request);
        return Result.ok().data("item",flag);
     }
     //获取订单信息
    @GetMapping("get-order-info/{courseId}")
    public Result getOrderVoInfoByCourseId(@PathVariable String courseId,HttpServletRequest request) throws HandlerException {
        OrderVo orderVo=orderService.getOrderVoInfoByCourseId(courseId,request);
         return Result.ok().data("item",orderVo);
    }

}

